# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Yigit Sever <yigit at yigitsever dot com>
# Contributor: Qontinuum <qontinuum@artixlinux.org>
# Contributor: timetoplatypus <timetoplatypus@protonmail.com>
# Contributor: andychu <andy@oilshell.org>

pkgname=oil
pkgver=0.18.0
pkgrel=1
pkgdesc='A new Unix shell'
arch=('loong64' 'x86_64')
url='https://www.oilshell.org'
license=('Apache')
depends=('glibc' 'gcc-libs' 'readline')
makedepends=('bash')
replaces=('osh')
install=oil.install
source=("$url/download/oils-for-unix-$pkgver.tar.gz")
sha256sums=('f5177ab35bb425f635b90e720b24b269f7a3915ca193f52c3e6223a02d0683f9')
b2sums=('a3c702f7214f1856864d344038b1c3fc1e1bd7732dbfdca2508a1eca7d18c1c3315fd3ea30bcd2898b96380e0ce76189756bb8741b4feb1f9fde4cff4afb02dc')
noextract=("oils-for-unix-$pkgver.tar.gz")
# https://www.oilshell.org/release/latest/

prepare() {
  # fix: LTO + strip
  mkdir -p path
  cat >path/c++ <<END
#!/bin/sh
exec g++ \$CXXFLAGS \$LDFLAGS -fPIC "\$@"
END
  cat >path/strip <<END
#!/bin/sh
exec cp -p "\$3" "\$2"
END
  chmod +x path/*

  # fix: bsdtar choking on hardlinked files pointing to self, e.g.:
  # _gen/frontend/option.asdl.h: Skipping hardlink pointing to itself: _gen/frontend/option.asdl.h: No such file or directory
  tar -xf "oils-for-unix-$pkgver.tar.gz"
}

build() {
  cd "oils-for-unix-$pkgver"

  ./configure \
    --prefix=/usr \
    --datarootdir=/usr/share

  PATH="$srcdir/path:$PATH" _build/oils.sh
}

package() {
  cd "oils-for-unix-$pkgver"

  DESTDIR="$pkgdir" ./install
}
